package com.multicert.hackathon;

import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;

import com.multicert.hackathon.blmanager.BaselineManagerImpl;

/**
 * @author rui.baeta@multicert.com
 */
@Mojo(name = "get-baselines")
public class GetBaselinesMojo extends AbstractBaselineMojo {

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        getLog().info(String.format("Retrieving existing baselines for project '%s'...", projectId));

        setBaselineManager(new BaselineManagerImpl(this.alfrescoUrl, this.username, this.password));
        try {
            List<String> baselines = getBaselineManager().getBaselines(projectId);
            for (String baseline : baselines) {
                getLog().info(String.format("baseline: %s", baseline));
            }
        } catch (Exception e) {
            getLog().error(e);
            throw new MojoFailureException(e.getMessage());
        }

        getLog().info(String.format("Baselines retrieved successfully."));
    }
}
